<template>
    <div>
        <breadcrumb :title="'首页管理'" :noBack="true"></breadcrumb>
        <div class="box white-block" v-loading="loading">
            <table-example :data="tableData" :tableColumn="header" :slotColumns="slotColumns" class="mt20">
                <!--接受scope-->
                <template slot="operate" slot-scope="scope">
                    <el-link type="primary" :underline="false" @click="jump(scope.row)">编辑</el-link>
                </template>
            </table-example>
            <page :data="data" v-if="data" class="mt20 page"></page>
        </div>
        <transition name="slide">
            <router-view @upload="getList"></router-view>
        </transition>
    </div>
</template>

<script>
    import breadcrumb from '../../components/breadcrumb'
    import tableExample from '../../components/table'
    import page from '../../components/pagination'

    export default {
        data() {
            return {
                tableData: [],
                header: [
                    {
                        prop: 'moduleName',
                        label: '模块',
                        minWidth: '33.3%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'lastUpdateTime',
                        label: '最后更新日期',
                        minWidth: '33.3%',
                        align: 'center',
                        headerAlign: 'center'
                    },
                    {
                        prop: 'operate',
                        label: '操作',
                        minWidth: '33.3%',
                        align: 'center',
                        headerAlign: 'center'
                    }
                ],
                slotColumns: ['operate'],
                data: {},
                loading: false,
                index: 1
            }
        },
        mounted() {
            this.getList()
        },
        methods: {
            getList(index) {
                this.loading = true
                if (index) this.index = index
                this.$http.get('/gsHomeManage/pageList', {
                    current: this.index || 1,
                    size: 10
                }).then(result => {
                    this.loading = false
                    if (result.success) {
                        this.tableData = result.data.records
                        this.data = result.data
                        delete this.data['records']
                    }
                    this.$method.updateView()
                }).catch(() => {
                    this.loading = false
                })
            },
            jump(row) {
                let url = '/'
                if (row.id === 1) url += 'banner'
                if (row.id === 2) url += 'hotProducts'
                if (row.id === 3) url += 'featuredProducts'
                if (row.id === 4) url += 'unitCooperation'
                this.$router.push(this.$route.path + url)
            }
        },
        components: {
            breadcrumb,
            tableExample,
            page
        }
    }
</script>
<style scoped lang="less">
    .box {
        padding-top: .8rem;
        padding-bottom: .8rem;
    }
</style>
